<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class data_service{
	private $CI;
	function __construct() { 
		$this->CI = &get_instance();
		$this->CI->load->model("Academia_job_model");
		$this->CI->load->model("Academic_report_model");
		$this->CI->load->model("Audit_model");
		$this->CI->load->model("Awards_model");
		$this->CI->load->model("Communication_model");
		$this->CI->load->model("Horizontal_project_model");
		$this->CI->load->model("Monograph_model");
		$this->CI->load->model("Paper_model");
		$this->CI->load->model("Patent_data_model");
		$this->CI->load->model("Patent_model");
		$this->CI->load->model("Research_report_model");
		$this->CI->load->model("Science_conversion_model");
		$this->CI->load->model("Technical_standard_model");
		$this->CI->load->model("Vertical_project_model");
		$this->CI->load->model("Admin_model");
	}

	/**  
	* 获取折线图数据统计
	* @access public 
	* @param  $type  成果类型
	* @param  $data_id  成果id
	*/  
	function getDatas($param=false)
	{	
		$role = explode(',', getSess()['sub_role_id']);
       	 array_push($role, getSess()['role_id']);

		// 部门筛选
		if(isset($param['dept']) && $param['dept']!=-1){
			$where=$this->CI->sqlEscape('dept_name=??',array($param['dept']));
		}else{			
			if(in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)||in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){
				$dept_data = array();
				foreach ((new Dept())->getAll() as $k => $v) {
					$dept_data[$k]['dept_name'] = $v[XPHEnum::Caption];
				}
			}else{      	
				$connar['items']="dept_name";
				$connar['groupby']="dept_name";
				$connar['where']=$this->CI->sqlEscape("status=??",array(CommonStatus::UnDeleted[XPHEnum::Value]));
				$dept_data=$this->CI->Admin_model->get_list_full($connar);
			}
	    	$dept_data= array_values(array_filter(array_column($dept_data, 'dept_name')));
	    	$dept='';  	
	    	foreach ($dept_data as $k => $v) {
	    		if($k==0){
	    			$dept="'".$v."'";
	    		}else{
	    			$dept.=",'".$v."'";	    			
	    		}
	    	};
			$where="dept_name in(".$dept.")";
		}		
		$where.=$this->CI->sqlEscape(' and status=??',array(ResultState::Publiced[XPHEnum::Value]));
		// 类型筛选
		if(isset($param['type'])&& $param['type']!=-1){
			$type=array($param['type']);
		}else{
			$type=(New ResultsType)->getAllValue();
		}
		/* ------------------------------------论文------------------------------------------------*/
		if(in_array(ResultsType::First[XPHEnum::Value], $type)){
			$data1['items']="if(publish_time,FROM_UNIXTIME(publish_time,'%Y'),'--') years,count(*) count";
			$data1['groupby']="years";
			$data1['orderby']="publish_time asc";
			$data1['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data1['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(publish_time,'%Y')=??",array($param['year']));
			}
			if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data1['where'] .= $this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and author=?? ', array($param['name']));
	  //       }
			$data1=$this->CI->Paper_model->get_list_full($data1);

			$data1_title=array_column($data1, 'years');
			$data1_data=array_column($data1, 'count');
			$data[]=array('table_name'=>reset($data1_title).'-'.end($data1_title).ResultsType::First[XPHEnum::Caption],'data'=>$data1_data,'title'=>$data1_title);
		}
		/* ------------------------------------专著------------------------------------------------*/
		if(in_array(ResultsType::Second[XPHEnum::Value], $type)){
			$data2['items']="FROM_UNIXTIME(publish_time,'%Y') years,count(*) count";
			$data2['groupby']="years";
			$data2['orderby']="publish_time asc";
			$data2['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data2['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(publish_time,'%Y')=??",array($param['year']));
			}
			if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data2['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
	        // if (isset($param['name'])) {
	        //     $connar['where'] .= $this->CI->sqlEscape(' and author=?? ', array($param['name']));
	        // }
			$data2=$this->CI->Monograph_model->get_list_full($data2);
			$data2_title=array_column($data2, 'years');
			$data2_data=array_column($data2, 'count');
			$data[]=array('table_name'=>reset($data2_title).'-'.end($data2_title).ResultsType::Second[XPHEnum::Caption],'data'=>$data2_data,'title'=>$data2_title);
		}
		// /* ------------------------------------专利------------------------------------------------*/
		if(in_array(ResultsType::Third[XPHEnum::Value], $type)){
			$data3['items']="FROM_UNIXTIME(announcement_date,'%Y') years,count(*) count";
			$data3['groupby']="years";
			$data3['orderby']="announcement_date asc";
			$data3['where']=$where;
	        // if (isset($param['name'])) {
	        //     $connar['where'] .= $this->CI->sqlEscape(' and author=?? ', array($param['name']));
	        // }
			if(isset($param['year']) && $param['year']!=''){
				$data3['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(announcement_date,'%Y')=??",array($param['year']));
			}
			if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data3['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			$data3=$this->CI->Patent_model->get_list_full($data3);
			$data3_title=array_column($data3, 'years');
			$data3_data=array_column($data3, 'count');
			$data[]=array('table_name'=>reset($data3_title).'-'.end($data3_title).ResultsType::Third[XPHEnum::Caption],'data'=>$data3_data,'title'=>$data3_title);
		}
		
		// /* ------------------------------------获奖------------------------------------------------*/
		if(in_array(ResultsType::Fourth[XPHEnum::Value], $type)){			
			$data4['items']="FROM_UNIXTIME(award_time,'%Y') years,count(*) count";
			$data4['groupby']="years";
			$data4['orderby']="award_time asc";
			$data4['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data4['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(award_time,'%Y')=??",array($param['year']));
			}
			if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data4['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
	        // if (isset($param['name'])) {
	        //     $connar['where'] .= $this->CI->sqlEscape(' and main_complete=?? ', array($param['name']));
	        // }
			$data4=$this->CI->Awards_model->get_list_full($data4);
			$data4_title=array_column($data4, 'years');
			$data4_data=array_column($data4, 'count');
			$data[]=array('table_name'=>reset($data4_title).'-'.end($data4_title).ResultsType::Fourth[XPHEnum::Caption],'data'=>$data4_data,'title'=>$data4_title);
		}
		// /* ------------------------------------研究报告、政策建议------------------------------------------------*/
		if(in_array(ResultsType::Fifth[XPHEnum::Value], $type)){
			$data5['items']="FROM_UNIXTIME(submit_date,'%Y') years,count(*) count";
			$data5['groupby']="years";
			$data5['orderby']="submit_date asc";
			$data5['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data5['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(submit_date,'%Y')=??",array($param['year']));
			}
			if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data5['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and author=?? ', array($param['name']));
	  //       }
			$data5=$this->CI->Research_report_model->get_list_full($data5);
			$data5_title=array_column($data5, 'years');
			$data5_data=array_column($data5, 'count');
			$data[]=array('table_name'=>reset($data5_title).'-'.end($data5_title).ResultsType::Fifth[XPHEnum::Caption],'data'=>$data5_data,'title'=>$data5_title);
		}
		
		// /* ------------------------------------技术标准------------------------------------------------*/
		if(in_array(ResultsType::Sixth[XPHEnum::Value], $type)){
			$data6['items']="FROM_UNIXTIME(publish_time,'%Y') years,count(*) count";
			$data6['groupby']="years";
			$data6['orderby']="publish_time asc";
			$data6['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data6['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(publish_time,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data6['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and completeor=?? ', array($param['name']));
	  //       }
			$data6=$this->CI->Technical_standard_model->get_list_full($data6);
			$data6_title=array_column($data6, 'years');
			$data6_data=array_column($data6, 'count');
			$data[]=array('table_name'=>reset($data6_title).'-'.end($data6_title).ResultsType::Sixth[XPHEnum::Caption],'data'=>$data6_data,'title'=>$data6_title);
		}
		
		// /* ------------------------------------纵向课题------------------------------------------------*/
		if(in_array(ResultsType::Seventh[XPHEnum::Value], $type)){
			$data7['items']="FROM_UNIXTIME(project_time,'%Y') years,count(*) count";
			$data7['groupby']="years";
			$data7['orderby']="project_time asc";
			$data7['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data7['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(project_time,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data7['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and head_name=?? ', array($param['name']));
	  //       }
			$data7=$this->CI->Vertical_project_model->get_list_full($data7);
			$data7_title=array_column($data7, 'years');
			$data7_data=array_column($data7, 'count');
			$data[]=array('table_name'=>reset($data7_title).'-'.end($data7_title).ResultsType::Seventh[XPHEnum::Caption],'data'=>$data7_data,'title'=>$data7_title);
		}
		
		// /* ------------------------------------横向课题------------------------------------------------*/
		if(in_array(ResultsType::Eighth[XPHEnum::Value], $type)){
			$data8['items']="FROM_UNIXTIME(project_time,'%Y') years,count(*) count";
			$data8['groupby']="years";
			$data8['orderby']="project_time asc";
			$data8['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data8['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(project_time,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data8['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and head_name=?? ', array($param['name']));
	  //       }
			$data8=$this->CI->Horizontal_project_model->get_list_full($data8);
			$data8_title=array_column($data8, 'years');
			$data8_data=array_column($data8, 'count');
			$data[]=array('table_name'=>reset($data8_title).'-'.end($data8_title).ResultsType::Eighth[XPHEnum::Caption],'data'=>$data8_data,'title'=>$data8_title);
		}
		
		// /* ------------------------------------科技转化情况------------------------------------------------*/
		if(in_array(ResultsType::Ninth[XPHEnum::Value], $type)){
			$data9['items']="FROM_UNIXTIME(time,'%Y') years,count(*) count";
			$data9['groupby']="years";
			$data9['time']="announcement_date asc";
			$data9['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data9['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(time,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data9['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and head_name=?? ', array($param['name']));
	  //       }
			$data9=$this->CI->Science_conversion_model->get_list_full($data9);
			$data9_title=array_column($data9, 'years');
			$data9_data=array_column($data9, 'count');
			$data[]=array('table_name'=>reset($data9_title).'-'.end($data9_title).ResultsType::Ninth[XPHEnum::Caption],'data'=>$data9_data,'title'=>$data9_title);
		}
		
		// /* ------------------------------------举办、参加学术交流会、学会年会------------------------------------------------*/
		if(in_array(ResultsType::Tenth[XPHEnum::Value], $type)){
			$data10['items']="FROM_UNIXTIME(time,'%Y') years,count(*) count";
			$data10['groupby']="years";
			$data10['time']="announcement_date asc";
			$data10['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data10['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(time,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data10['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           // 没有找到成果人字段
	  //           $connar['where'] .= $this->CI->sqlEscape(' and 1<>?? ', array(1));
	  //       }
			$data10=$this->CI->Communication_model->get_list_full($data10);
			$data10_title=array_column($data10, 'years');
			$data10_data=array_column($data10, 'count');
			$data[]=array('table_name'=>reset($data10_title).'-'.end($data10_title).ResultsType::Tenth[XPHEnum::Caption],'data'=>$data10_data,'title'=>$data10_title);
		}
		
		// /* ------------------------------------学术报告情况------------------------------------------------*/
		if(in_array(ResultsType::Eleventh[XPHEnum::Value], $type)){
			$data11['items']="FROM_UNIXTIME(time,'%Y') years,count(*) count";
			$data11['groupby']="years";
			$data11['orderby']="time asc";
			$data11['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data11['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(time,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data11['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
			// 	// 没有找到成果人字段
	  //           $connar['where'] .= $this->CI->sqlEscape(' and 1<>?? ', array(1));
	  //       }
			$data11=$this->CI->Academic_report_model->get_list_full($data11);
			$data11_title=array_column($data11, 'years');
			$data11_data=array_column($data11, 'count');
			$data[]=array('table_name'=>reset($data11_title).'-'.end($data11_title).ResultsType::Eleventh[XPHEnum::Caption],'data'=>$data11_data,'title'=>$data11_title);
		}
				
		// /* ------------------------------------学术兼职情况------------------------------------------------*/
		if(in_array(ResultsType::Twelfth[XPHEnum::Value], $type)){
			$data12['items']="FROM_UNIXTIME(created,'%Y') years,count(*) count";
			$data12['groupby']="years";
			$data12['orderby']="created asc";//没有兼职时间，这里暂时使用创建时间
			$data12['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data12['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(created,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data12['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and name=?? ', array($param['name']));
	  //       }
			$data12=$this->CI->Academia_job_model->get_list_full($data12);
			$data12_title=array_column($data12, 'years');
			$data12_data=array_column($data12, 'count');
			$data[]=array('table_name'=>reset($data12_title).'-'.end($data12_title).ResultsType::Twelfth[XPHEnum::Caption],'data'=>$data12_data,'title'=>$data12_title);
		}
		// /* ------------------------------------学科平台-----------------------------------------------*/
		if(in_array(ResultsType::Thirteen[XPHEnum::Value], $type)){
			$data13['items']="FROM_UNIXTIME(created,'%Y') years,count(*) count";
			$data13['groupby']="years";
			$data13['orderby']="created asc";//没有兼职时间，这里暂时使用创建时间
			$data13['where']=$where;
			if(isset($param['year']) && $param['year']!=''){
				$data13['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(created,'%Y')=??",array($param['year']));
			}if(isset($param['submit_year']) && $param['submit_year']!=''){
				$data13['where'].=$this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
			}
			// if (isset($param['name'])) {
	  //           $connar['where'] .= $this->CI->sqlEscape(' and name=?? ', array($param['name']));
	  //       }
			$data13=$this->CI->Subject_platform_model->get_list_full($data13);
			$data13_title=array_column($data13, 'years');
			$data13_data=array_column($data13, 'count');
			$data[]=array('table_name'=>reset($data13_title).'-'.end($data13_title).ResultsType::Thirteen[XPHEnum::Caption],'data'=>$data13_data,'title'=>$data13_title);
		}
		
		
		if(!isset($data)){
			$data=array();
		}

		return retJson('图标数据',true,$data);
	}


	/**  
	* 获取柱状图数据统计
	* @access public 
	* @param  $type  成果类型
	* @param  $data_id  成果id
	*/  
	function getDatas1($param=false)
	{
		  $role = explode(',', getSess()['sub_role_id']);
        array_push($role, getSess()['role_id']);

        if(in_array(WebRole::SchoolLeader[XPHEnum::Value], $role)||in_array(WebRole::Sscientifictaff[XPHEnum::Value], $role)){
            $dept_data = array();
            foreach ((new Dept())->getAll() as $k => $v) {
                $dept_data[$k]['dept_name'] = $v[XPHEnum::Caption];
            }
        }else{      	
			$connar['items']="dept_name";
	    	$connar['groupby']="dept_name";
	    	$connar['where']=$this->CI->sqlEscape("status=??",array(CommonStatus::UnDeleted[XPHEnum::Value]));
	    	$dept_data=$this->CI->Admin_model->get_list_full($connar);
	    }
    	$dept_data=array_column($dept_data, 'dept_name');

		$dept_data1 = array(); $case = "when dept_name = '公共基础教学部（体育部）、马克思主义学院' then '公共基础教学部'";
		foreach ((new addDept())->getAll() as $k => $v) {
			if($v[XPHEnum::Alternate] > 100 && $v[XPHEnum::Alternate] < 200){
				$dept_data1[$k]= $v[XPHEnum::Caption];
				$case .= "when dept_name = '".$v[XPHEnum::Caption]."' then '职能管理部'";
			}
		}
		$dept_data = array_merge($dept_data, $dept_data1);

		$dept="'".implode("','",$dept_data)."'";
    	// $dept='';
    	
    	// foreach ($dept_data as $k => $v) {

    	// 	if($k==0){
    	// 		$dept="'".$v."'";
    	// 	}else{
    	// 		$dept.=",'".$v."'";	    			
    	// 	}
    	// };
		$where="dept_name in(".$dept.")";
		$where.=$this->CI->sqlEscape(' and status=?? and is_del=??',array(ResultState::Publiced[XPHEnum::Value],CommonWhether::Not[XPHEnum::Value]));
		// if(isset($param['dept']) && $param['dept']!='-1'){
		// 	$where.=$this->CI->sqlEscape(" and dept_name=??",array($param['dept']));
		// }
		if(isset($param['dept']) && $param['dept']!='-1'){
			if (strpos($param['dept'],'分院') !== false) {
				$deptname = strstr($param['dept'], '分院', true);
				$where .= " and dept_name like '%".$deptname."%'";
			}else if($param['dept'] == '职能管理部'){
				$dept_data = array();
				foreach ((new addDept())->getAll() as $k => $v) {
					if($v[XPHEnum::Alternate] > 100 && $v[XPHEnum::Alternate] < 200){
						$dept_data[$k]= $v[XPHEnum::Caption];
					}
				}
				$dept_data[count($dept_data)] = '职能管理部';
			   $deptnames = implode("','",$dept_data);
			   $where  .= " and dept_name in ('".$deptnames."')";

			}else{
				$where  .= $this->CI->sqlEscape(' and dept_name=?? ', array($param['dept'])); 
			}
		}

		if(isset($param['type']) && $param['type']!='-1'){
			$type=array($param['type']);
		}else{
			$type=(new ResultsType)->getAllValue();
		}

		$caseitems = "(case ".$case." else dept_name end ) as dept_name,";

		/* ------------------------------------论文------------------------------------------------*/
		if(in_array(ResultsType::First[XPHEnum::Value], $type)) {
			// $data1['items']="db_paper.dept_name,	count(*) count,IF(db_paper.publish_time='','--',DATE_FORMAT( FROM_UNIXTIME( db_paper.publish_time), '%Y' )) publish_time,db_paper.id";
			$data1['items']=$caseitems."IF(db_paper.publish_time='','--',DATE_FORMAT( FROM_UNIXTIME( db_paper.publish_time), '%Y' )) publish_time,db_paper.id";
			// $data1['groupby']="db_paper.publish_time,db_paper.dept_name";
			// $data1['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data1['where']=$where;
            $data1['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::First[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_paper.id');
            if (isset($param['year']) && $param['year'] != '') {
                $data1['where'] .= $this->CI->sqlEscape(' and DATE_FORMAT(FROM_UNIXTIME(publish_time), "%Y" ) =?? ', array($param['year']));
            }
            if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data1['where'] .= $this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
            }
			// if(isset($param['year']) && $param['year']!=''){
			// 	$data1['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(publish_time,'%Y')=??",array($param['year']));
			// }
			if (isset($param['name'])  && $param['name']!=-1 && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data1['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::First[XPHEnum::Value].') author1','author1.data_id=db_paper.id');
                 $data1['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));

	            // $data1['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name,$identity));
	        }
			$data1=$this->CI->Paper_model->get_list_full($data1);
			//重新拼接排序
			$sql = $this->CI->db->last_query();
			$sql1 = "select *,count(*)as count from (".$sql.")  p  GROUP BY publish_time,dept_name order by FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','公共基础教学部','职能管理部','外单位','校领导')
			";
			// echo $sql1;
			$data1=$this->CI->Paper_model->query($sql1);

			$year_list = array_values(array_unique( array_column($data1,'publish_time'))) ;
			$dept_list = array_values(array_unique(array_column($data1,'dept_name')));

			// var_dump($data1);
			// var_dump($year_list);
			// var_dump($dept_list);

			if($data1){
				//数组去重,相同条件的数量累加
					/* $result=array();				
					foreach($data1 as $val){
							$key = $val['dept_name'].'_'.$val['publish_time'];
							if(!isset($result[$key])){
								$result[$key] = $val;
							}else{
								$result[$key]['count'] = $val['count'];
							}
						
					}
					$result = array_values($result);
					// 获取标题
					foreach ($result as $k => $v) {
						$data1_title[$v['publish_time']][]=$v;	
						$data1_data[$v['dept_name']][]=$v;
					}

					// 生成数据		
					$data1_title=array_keys($data1_title);
					foreach ($data1_data as $k => $v) {
						$a = array();$b = array();
						foreach ($v as $k1 => $v1) {
							$a[$k1]=$v1['count'];
							$b[$k1]=$v1['publish_time'];
						}
						// 不存在的数据填充0
						$diff=array_diff($data1_title,$b);
						foreach ($diff as $k1 => $v1) {
							array_splice($a,$k1,0,0);
						}
						$color = (new Dept())->showRemark($data1_data[$k][0]['dept_name']);
						$data1_score[$k]=array('data'=>$a,'name'=>$data1_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
						$a=array();
					}	 
					$data1_dept=array_keys($data1_data); */

				// var_dump($data1_score);

				$result=array();				
				foreach($data1 as $val){
						$key = $val['dept_name'].'_'.$val['publish_time'];
						$result[$key] = $val['count'];
					
				}
				$data1_score = array();
				foreach($dept_list as $k=>$v){
					foreach($year_list as $k1=>$v1){
						if(isset($result[$v.'_'.$v1])){
							$data1_score[$v]['data'][] = $result[$v.'_'.$v1];
						}else{
							$data1_score[$v]['data'][] = 0;
						}
					}
					$data1_score[$v]['name'] = $v;
					$data1_score[$v]['type'] = 'bar';
					$data1_score[$v]['color'] = (new Dept())->showRemark($v);
					
				}

				// $year_list = array_map(function($value) {
				// 	return (string)$value;
				// }, $year_list);

				$data[]=array('table_name'=>reset($year_list).'-'.end($year_list).ResultsType::First[XPHEnum::Caption],'data'=>$data1_score,'title'=>$year_list,'dept_name'=>$dept_list);
				// var_dump($data);
				// $data[]=array('table_name'=>reset($data1_title).'-'.end($data1_title).ResultsType::First[XPHEnum::Caption],'data'=>$data1_score,'title'=>$data1_title,'dept_name'=>$data1_dept);
				// $a=array();
				// $b=array();
			}
		}
		/* ------------------------------------专著------------------------------------------------*/
		if(in_array(ResultsType::Second[XPHEnum::Value], $type)) {
			$data2['items']="if(db_monograph.publish_time='','--',FROM_UNIXTIME(db_monograph.publish_time,'%Y')) publish_time,count(*) count,db_monograph.dept_name";
			$data2['groupby']="db_monograph.publish_time,db_monograph.dept_name";
			$data2['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data2['where']=$where;
            $data2['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Second[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_monograph.id');
			if(isset($param['year']) && $param['year']!=''){
				$data2['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_monograph.publish_time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data2['where'] .= $this->CI->sqlEscape(' and db_monograph.award_year=?? ', array($param['submit_year']));
            }
	        if (isset($param['name'])  && $param['name']!=-1) {
	        	$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data2['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Second[XPHEnum::Value].') author1','author1.data_id=db_monograph.id');
                 $data2['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));

	           // $data2['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data2=$this->CI->Monograph_model->get_list_full($data2);

			
			if($data2){
				$result=array();				
	            foreach($data2 as $val){
	                $key = $val['dept_name'].'_'.$val['publish_time'];
	                if(!isset($result[$key])){
	                    $result[$key] = $val;
	                }else{
	                    $result[$key]['count'] += $val['count'];
	                }
	            }

	            $result = array_values($result);

				// 获取标题
				foreach ($result as $k => $v) {
					$data2_title[$v['publish_time']][]=$v;	
					$data2_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data2_title=array_keys($data2_title);
				foreach ($data2_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['publish_time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data2_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data2_data[$k][0]['dept_name']);
					$data2_score[$k]=array('data'=>$a,'name'=>$data2_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data2_dept=array_keys($data2_data);
				$data[]=array('table_name'=>reset($data2_title).'-'.end($data2_title).ResultsType::Second[XPHEnum::Caption],'data'=>$data2_score,'title'=>$data2_title,'dept_name'=>$data2_dept);
		
				$a=array();
				$b=array();
			}
		}
		/* ------------------------------------专利------------------------------------------------*/
		if(in_array(ResultsType::Third[XPHEnum::Value], $type)) {
			$data3['items']="if(db_patent.announcement_date='','--',FROM_UNIXTIME(db_patent.announcement_date,'%Y'))  announcement_date,count(*) count,db_patent.dept_name";
			$data3['groupby']="db_patent.announcement_date,db_patent.dept_name";
			$data3['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data3['where']=$where;
            $data3['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Third[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_patent.id');
			if(isset($param['year']) && $param['year']!=''){
				$data3['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_patent.announcement_date,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data3['where'] .= $this->CI->sqlEscape(' and db_patent.award_year=?? ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data3['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Third[XPHEnum::Value].') author1','author1.data_id=db_patent.id');
                 $data3['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	          //  $data3['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data3=$this->CI->Patent_model->get_list_full($data3);
			if($data3){
				$result=array();				
	            foreach($data3 as $val){
	                $key = $val['dept_name'].'_'.$val['announcement_date'];
	                if(!isset($result[$key])){
	                    $result[$key] = $val;
	                }else{
	                    $result[$key]['count'] += $val['count'];
	                }
	            }

	            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data3_title[$v['announcement_date']][]=$v;	
					$data3_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data3_title=array_keys($data3_title);
				foreach ($data3_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['announcement_date'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data3_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data3_data[$k][0]['dept_name']);
					$data3_score[$k]=array('data'=>$a,'name'=>$data3_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data3_dept=array_keys($data3_data);
				$data[]=array('table_name'=>reset($data3_title).'-'.end($data3_title).ResultsType::Third[XPHEnum::Caption],'data'=>$data3_score,'title'=>$data3_title,'dept_name'=>$data3_dept);
				$a=array();
				$b=array();
			}
		}
		
		/* ------------------------------------获奖------------------------------------------------*/
		if(in_array(ResultsType::Fourth[XPHEnum::Value], $type)) {
			$data4['items']="if(db_awards.award_time='','--',FROM_UNIXTIME(db_awards.award_time,'%Y'))  award_time,count(*) count,db_awards.dept_name";
			$data4['groupby']="db_awards.award_time,db_awards.dept_name";
			$data4['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data4['where']=$where;
            $data4['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Fourth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_awards.id');
			if(isset($param['year']) && $param['year']!=''){
				$data4['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(award_time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data4['where'] .= $this->CI->sqlEscape(' and award_year=?? ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
	           // $data4['where'] .=$this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	            $data4['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Fourth[XPHEnum::Value].') author1','author1.data_id=db_awards.id');
                 $data4['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	        }

			$data4=$this->CI->Awards_model->get_list_full($data4);
			if($data4){
				$result=array();				
	            foreach($data4 as $val){
	                $key = $val['dept_name'].'_'.$val['award_time'];
	                if(!isset($result[$key])){
	                    $result[$key] = $val;
	                }else{
	                    $result[$key]['count'] += $val['count'];
	                }
	            }

	            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data4_title[$v['award_time']][]=$v;	
					$data4_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data4_title=array_keys($data4_title);
				foreach ($data4_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['award_time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data4_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data4_data[$k][0]['dept_name']);
					$data_score4[$k]=array('data'=>$a,'name'=>$data4_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data4_dept=array_keys($data4_data);
				$data[]=array('table_name'=>reset($data4_title).'-'.end($data4_title).ResultsType::Fourth[XPHEnum::Caption],'data'=>$data_score4,'title'=>$data4_title,'dept_name'=>$data4_dept);
				$a=array();
				$b=array();
			}
		}		
		/* ------------------------------------研究报告、政策建议------------------------------------------------*/
		if(in_array(ResultsType::Fifth[XPHEnum::Value], $type)) {
			$data5['items']="if(db_research_report.submit_date='','--',FROM_UNIXTIME(db_research_report.submit_date,'%Y')) submit_date,db_research_report.dept_name,count(*) count";
			$data5['groupby']="db_research_report.submit_date,db_research_report.dept_name";
			$data5['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data5['where']=$where;
            $data5['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Fifth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_research_report.id');
			if(isset($param['year']) && $param['year']!=''){
				$data5['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_research_report.submit_date,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data5['where'] .= $this->CI->sqlEscape(' and db_research_report.award_year=?? ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data5['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Fifth[XPHEnum::Value].') author1','author1.data_id=db_research_report.id');
                 $data5['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	            // $data5['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data5=$this->CI->Research_report_model->get_list_full($data5);
			if($data5){
				$result=array();				
	            foreach($data5 as $val){
	                $key = $val['dept_name'].'_'.$val['submit_date'];
	                if(!isset($result[$key])){
	                    $result[$key] = $val;
	                }else{
	                    $result[$key]['count'] += $val['count'];
	                }
	            }

	            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data5_title[$v['submit_date']][]=$v;	
					$data5_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data5_title=array_keys($data5_title);
				foreach ($data5_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['submit_date'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data5_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data5_data[$k][0]['dept_name']);
					$data_score5[$k]=array('data'=>$a,'name'=>$data5_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data5_dept=array_keys($data5_data);
				$data[]=array('table_name'=>reset($data5_title).'-'.end($data5_title).ResultsType::Fifth[XPHEnum::Caption],'data'=>$data_score5,'title'=>$data5_title,'dept_name'=>$data5_dept);
				$a=array();
				$b=array();
			}
		}
			/* ------------------------------------技术标准------------------------------------------------*/
			if(in_array(ResultsType::Sixth[XPHEnum::Value], $type)) {
				$data6['items']="if(db_technical_standard.publish_time='','--',FROM_UNIXTIME(db_technical_standard.publish_time,'%Y')) publish_time,db_technical_standard.dept_name,count(*) count";
				$data6['groupby']="db_technical_standard.publish_time,db_technical_standard.dept_name";
				$data6['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
				$data6['where']=$where;
	            $data6['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Sixth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_technical_standard.id');
				if(isset($param['year']) && $param['year']!=''){
					$data6['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_technical_standard.publish_time,'%Y')=??",array($param['year']));
				}
				if (isset($param['submit_year']) && $param['submit_year'] != '') {
	                $data6['where'] .= $this->CI->sqlEscape('  and db_technical_standard.award_year=?? ', array($param['submit_year']));
	            }
				if (isset($param['name'])  && $param['name']!=-1) {
					$name_arr = explode(",",$param['name']);
                   $name = $name_arr[0];
                   $identity = $name_arr[1];
                    $data6['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Sixth[XPHEnum::Value].') author1','author1.data_id=db_technical_standard.id');
                 $data6['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
		           // $data6['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
		        }
				$data6=$this->CI->Technical_standard_model->get_list_full($data6);

				if($data6){
					$result=array();				
		            foreach($data6 as $val){
		                $key = $val['dept_name'].'_'.$val['publish_time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
					// 获取标题
					foreach ($result as $k => $v) {
						$data6_title[$v['publish_time']][]=$v;	
						$data6_data[$v['dept_name']][]=$v;
					}
					// 生成数据		
					$data6_title=array_keys($data6_title);
					foreach ($data6_data as $k => $v) {
						$a = array();$b = array();
						foreach ($v as $k1 => $v1) {
							$a[$k1]=$v1['count'];
							$b[$k1]=$v1['publish_time'];
						}
						// 不存在的数据填充0
						$diff=array_diff($data6_title,$b);
						foreach ($diff as $k1 => $v1) {
							array_splice($a,$k1,0,0);
						}
						$color = (new Dept())->showRemark($data6_data[$k][0]['dept_name']);
						$data_score6[$k]=array('data'=>$a,'name'=>$data6_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
						$a=array();
					}		
					$data6_dept=array_keys($data6_data);
					$data[]=array('table_name'=>reset($data6_title).'-'.end($data6_title).ResultsType::Sixth[XPHEnum::Caption],'data'=>$data_score6,'title'=>$data6_title,'dept_name'=>$data6_dept);
					$a=array();
					$b=array();
				}
			}
	
		/* ------------------------------------纵向课题------------------------------------------------*/
		if(in_array(ResultsType::Seventh[XPHEnum::Value], $type)) {
			$data7['items']="if(db_vertical_project.project_time='','--',FROM_UNIXTIME(db_vertical_project.project_time,'%Y')) project_time,db_vertical_project.dept_name,count(*) count";
			$data7['groupby']="db_vertical_project.project_time,db_vertical_project.dept_name";
			$data7['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data7['where']=$where;
            $data7['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Seventh[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_vertical_project.id');
			if(isset($param['year']) && $param['year']!=''){
				$data7['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_vertical_project.project_time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data7['where'] .= $this->CI->sqlEscape('  and db_vertical_project.award_year=??  ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data7['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Seventh[XPHEnum::Value].') author1','author1.data_id=db_vertical_project.id');
                 $data7['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	           // $data7['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data7=$this->CI->Vertical_project_model->get_list_full($data7);
			if($data7){
					$result=array();				
		            foreach($data7 as $val){
		                $key = $val['dept_name'].'_'.$val['project_time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data7_title[$v['project_time']][]=$v;	
					$data7_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data7_title=array_keys($data7_title);
				foreach ($data7_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['project_time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data7_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data7_data[$k][0]['dept_name']);
					$data_score7[$k]=array('data'=>$a,'name'=>$data7_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data7_dept=array_keys($data7_data);
				$data[]=array('table_name'=>reset($data7_title).'-'.end($data7_title).ResultsType::Seventh[XPHEnum::Caption],'data'=>$data_score7,'title'=>$data7_title,'dept_name'=>$data7_dept);
				$a=array();
				$b=array();
			}
		}		
		/*------------------------------------横向课题------------------------------------------------*/
		if(in_array(ResultsType::Eighth[XPHEnum::Value], $type)) {
			$data8['items']="if(db_horizontal_project.project_time='','--',FROM_UNIXTIME(db_horizontal_project.project_time,'%Y')) project_time,db_horizontal_project.dept_name,count(*) count";
			$data8['groupby']="db_horizontal_project.project_time,db_horizontal_project.dept_name";
			$data8['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data8['where']=$where;
            $data8['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Eighth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_horizontal_project.id');
			if(isset($param['year']) && $param['year']!=''){
				$data8['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_horizontal_project.project_time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data8['where'] .= $this->CI->sqlEscape('  and db_horizontal_project.award_year=??  ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data8['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Eighth[XPHEnum::Value].') author1','author1.data_id=db_horizontal_project.id');
                 $data8['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	         //   $data8['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data8=$this->CI->Horizontal_project_model->get_list_full($data8);
			if($data8){
					$result=array();				
		            foreach($data8 as $val){
		                $key = $val['dept_name'].'_'.$val['project_time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data8_title[$v['project_time']][]=$v;	
					$data8_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data8_title=array_keys($data8_title);
				foreach ($data8_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['project_time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data8_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data8_data[$k][0]['dept_name']);
					$data_score8[$k]=array('data'=>$a,'name'=>$data8_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data8_dept=array_keys($data8_data);
				$data[]=array('table_name'=>reset($data8_title).'-'.end($data8_title).ResultsType::Eighth[XPHEnum::Caption],'data'=>$data_score8,'title'=>$data8_title,'dept_name'=>$data8_dept);
				$a=array();
				$b=array();
			}
		}		
		/* ------------------------------------科技转化情况------------------------------------------------*/
		if(in_array(ResultsType::Ninth[XPHEnum::Value], $type)) {
			$data9['items']="if(db_science_conversion.time='','--',FROM_UNIXTIME(db_science_conversion.time,'%Y')) time,count(*) count,db_science_conversion.dept_name";
			$data9['groupby']="db_science_conversion.time,db_science_conversion.dept_name";
			$data9['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data9['where']=$where;
            $data9['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Ninth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_science_conversion.id');
			if(isset($param['year']) && $param['year']!=''){
				$data9['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_science_conversion.time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data9['where'] .= $this->CI->sqlEscape(' and db_science_conversion.award_year=?? ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data9['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Ninth[XPHEnum::Value].') author1','author1.data_id=db_science_conversion.id');
                 $data9['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	          //  $data9['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data9=$this->CI->Science_conversion_model->get_list_full($data9);
			if($data9){
					$result=array();				
		            foreach($data9 as $val){
		                $key = $val['dept_name'].'_'.$val['time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data9_title[$v['time']][]=$v;	
					$data9_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data9_title=array_keys($data9_title);
				foreach ($data9_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data9_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data9_data[$k][0]['dept_name']);
					$data_score9[$k]=array('data'=>$a,'name'=>$data9_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data9_dept=array_keys($data9_data);
				$data[]=array('table_name'=>reset($data9_title).'-'.end($data9_title).ResultsType::Ninth[XPHEnum::Caption],'data'=>$data_score9,'title'=>$data9_title,'dept_name'=>$data9_dept);
				$a=array();
				$b=array();
			}
		}		
		/* ------------------------------------举办、参加学术交流会、学会年会------------------------------------------------*/
		if(in_array(ResultsType::Tenth[XPHEnum::Value], $type)) {
			$data10['items']="if(time='','--',FROM_UNIXTIME(time,'%Y')) time,dept_name,count(*) count";
			$data10['groupby']="time,dept_name";
			$data10['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data10['where']=$where;
            $data10['join']=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Tenth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_communication.id');
			if(isset($param['year']) && $param['year']!=''){
				$data10['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data10['where'] .= $this->CI->sqlEscape('  and award_year=?? ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				// 没有成果有人
	            $data10['where'] .= $this->CI->sqlEscape(' and 1<>?? ', array(1));
	        }
			$data10=$this->CI->Communication_model->get_list_full($data10);
			if($data10){
					$result=array();				
		            foreach($data10 as $val){
		                $key = $val['dept_name'].'_'.$val['time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data10_title[$v['time']][]=$v;	
					$data10_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data10_title=array_keys($data10_title);
				foreach ($data10_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data10_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data10_data[$k][0]['dept_name']);
					$data_score10[$k]=array('data'=>$a,'name'=>$data10_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data10_dept=array_keys($data10_data);
				$data[]=array('table_name'=>reset($data10_title).'-'.end($data10_title).ResultsType::Tenth[XPHEnum::Caption],'data'=>$data_score10,'title'=>$data10_title,'dept_name'=>$data10_dept);
				$a=array();
				$b=array();
			}
		}		
		/* ------------------------------------学术报告情况------------------------------------------------*/
		if(in_array(ResultsType::Eleventh[XPHEnum::Value], $type)) {
			$data11['items']="if(time='','--',FROM_UNIXTIME(time,'%Y')) time,dept_name,count(*) count";
			$data11['groupby']="time,dept_name";
			$data11['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data11['where']=$where;
            $data11['join']=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Twelfth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_academic_report.id');
			if(isset($param['year']) && $param['year']!=''){
				$data11['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data11['where'] .= $this->CI->sqlEscape('  and award_year=?? ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				// 没有成果有人
	            $data11['where'] .= $this->CI->sqlEscape(' and 1<>?? ', array(1));
	        }
			$data11=$this->CI->Academic_report_model->get_list_full($data11);
			if($data11){
					$result=array();				
		            foreach($data11 as $val){
		                $key = $val['dept_name'].'_'.$val['time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data11_title[$v['time']][]=$v;	
					$data11_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data11_title=array_keys($data11_title);
				foreach ($data11_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data11_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data11_data[$k][0]['dept_name']);
					$data_score[$k]=array('data'=>$a,'name'=>$data11_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data11_dept=array_keys($data11_data);
				$data[]=array('table_name'=>reset($data11_title).'-'.end($data11_title).ResultsType::Eleventh[XPHEnum::Caption],'data'=>$data_score,'title'=>$data11_title,'dept_name'=>$data11_dept);
				$a=array();
				$b=array();	
			}	
		}		
		/* ------------------------------------学术兼职情况------------------------------------------------*/
		if(in_array(ResultsType::Twelfth[XPHEnum::Value], $type)) {
			$data12['items']=" if(db_academia_job.created='','--',FROM_UNIXTIME(db_academia_job.created,'%Y')) created,db_academia_job.dept_name,count(*) count";
			$data12['groupby']="db_academia_job.created,db_academia_job.dept_name";
			$data12['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data12['where']=$where;
            $data12['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Twelfth[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_academia_job.id');
			if(isset($param['year']) && $param['year']!=''){
				$data12['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_academia_job.created,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data12['where'] .= $this->CI->sqlEscape('  and db_academia_job.award_year=??  ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data12['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Twelfth[XPHEnum::Value].') author1','author1.data_id=db_academia_job.id');
                 $data12['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	           // $data12['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data12=$this->CI->Academia_job_model->get_list_full($data12);
			if($data12){
					$result=array();				
		            foreach($data12 as $val){
		                $key = $val['dept_name'].'_'.$val['created'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data12_title[$v['created']][]=$v;	
					$data12_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data12_title=array_keys($data12_title);
				foreach ($data12_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['created'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data12_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data12_data[$k][0]['dept_name']);
					$data_score12[$k]=array('data'=>$a,'name'=>$data12_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data12_dept=array_keys($data12_data);
				$data[]=array('table_name'=>reset($data12_title).'-'.end($data12_title).ResultsType::Twelfth[XPHEnum::Caption],'data'=>$data_score12,'title'=>$data12_title,'dept_name'=>$data12_dept);
				$a=array();
				$b=array();
			}
		}		
		/* ------------------------------------学科平台------------------------------------------------*/
		if(in_array(ResultsType::Thirteen[XPHEnum::Value], $type)) {
			$data13['items']="if(db_subject_platform.receive_time='','--', FROM_UNIXTIME(db_subject_platform.receive_time,'%Y')) receive_time,db_subject_platform.dept_name,count(*) count";
			$data13['groupby']="db_subject_platform.receive_time,db_subject_platform.dept_name";
			$data13['orderby']="FIELD(dept_name,'机电分院','机械工程分院','电气电子工程分院','建筑工程分院','财经分院','商贸分院','交通分院','设计与艺术分院','鉴湖分院','人文社科部','职能管理部','外单位','校领导')";
			$data13['where']=$where;
            $data13['join'][0]=array('(select group_concat(db_author.author_name) author,group_concat(db_author.identity) identity,data_id FROM db_author WHERE db_author.type = '.ResultsType::Thirteen[XPHEnum::Value].'  GROUP BY db_author.data_id ) author','author.data_id=db_subject_platform.id');
			if(isset($param['year']) && $param['year']!=''){
				$data13['where'].=$this->CI->sqlEscape(" and FROM_UNIXTIME(db_subject_platform.receive_time,'%Y')=??",array($param['year']));
			}
			if (isset($param['submit_year']) && $param['submit_year'] != '') {
                $data13['where'] .= $this->CI->sqlEscape(' and db_subject_platform.award_year=??  ', array($param['submit_year']));
            }
			if (isset($param['name'])  && $param['name']!=-1) {
				$name_arr = explode(",",$param['name']);
                $name = $name_arr[0];
                $identity = $name_arr[1];
                 $data13['join'][1]=array('(select * from db_author where db_author.type='.ResultsType::Thirteen[XPHEnum::Value].') author1','author1.data_id=db_subject_platform.id');
                 $data13['where'] .= $this->CI->sqlEscape(' and find_in_set(??,author1.author_name) and find_in_set(??,author1.identity) ', array($name,$identity));
	           // $data13['where'] .= $this->CI->sqlEscape('  and find_in_set(??,author.author) and find_in_set(??,author.identity)', array($name, $identity));
	        }
			$data13=$this->CI->Subject_platform_model->get_list_full($data13);
			
			if($data13){
					$result=array();				
		            foreach($data13 as $val){
		                $key = $val['dept_name'].'_'.$val['receive_time'];
		                if(!isset($result[$key])){
		                    $result[$key] = $val;
		                }else{
		                    $result[$key]['count'] += $val['count'];
		                }
		            }

		            $result = array_values($result);
				// 获取标题
				foreach ($result as $k => $v) {
					$data13_title[$v['receive_time']][]=$v;	
					$data13_data[$v['dept_name']][]=$v;
				}
				// 生成数据		
				$data13_title=array_keys($data13_title);
				foreach ($data13_data as $k => $v) {
					$a = array();$b = array();
					foreach ($v as $k1 => $v1) {
						$a[$k1]=$v1['count'];
						$b[$k1]=$v1['receive_time'];
					}
					// 不存在的数据填充0
					$diff=array_diff($data13_title,$b);
					foreach ($diff as $k1 => $v1) {
						array_splice($a,$k1,0,0);
					}
					$color = (new Dept())->showRemark($data13_data[$k][0]['dept_name']);
					$data_score[$k]=array('data'=>$a,'name'=>$data13_data[$k][0]['dept_name'],'type'=>'bar','color'=>$color);
					$a=array();
				}		
				$data13_dept=array_keys($data13_data);
				$data[]=array('table_name'=>reset($data13_title).'-'.end($data13_title).ResultsType::Thirteen[XPHEnum::Caption],'data'=>$data_score,'title'=>$data13_title,'dept_name'=>$data13_dept);
				$a=array();
				$b=array();
			}
		}		
		if(!isset($data)){
			$data=array();
		}

		return retJson('图标数据',true,$data);
	}

}